Post

Replies

Boosts

Views

Activity

How to align slider labels in SwiftUI
On macOS we can add labels directly to SwiftUI slider. Has someone found a way how we can align two or more sliders in a VStack?- label text right aligned- all labels should have the same width (given by the largest text)- all slider bars should have the same but flexible width within the containers frame
4
0
4.0k
Dec ’19
How to add a label to the side of a TextField on macOS
In the latest beta most of the SwiftUI controls have now a labels that are displayed on the left side of the controls. The alignment of the controls and labels works pretty well. Also the TextField is aligned with the other controls. But its title parameter is used as a placeholder inside the TextField while the left side of the TextField is empty. In my application I have a SwiftUI form with some controls and some number input fields. After the user has entered values the placeholders are not visible and the user cannot see the meaning of each value he entered anymore. Is there a way that the title of a TextField can be displayed as a label on the left side similar to the other controls instead of a placeholder inside the input field?
2
0
1.2k
Jul ’20
Swift TextField with label on macOS
Why is there no label for SwiftUI TextField but only a placeholder text? Or is there a modifier that I haven't found yet or a style property? On macOS every control seems to have now a label that is shown on the left side and that is correctly aligned with the other controls in a form. The TextField is also aligned with the other controls but has an empty space left to it. Using the label parameter as a placeholder is not very helpful having multiple textfields and the user entered already some values in them. In this case you cannot see anymore the meaning for all these values. I tried to implement a HStack with a Text and a TextField as a workaround but had trouble to align it with the other controls that have already label parameters in their SwiftUI syntax.
2
0
1.8k
Jul ’20
How to add a label to a SwiftUI Textfield in macOS
Is there a way to add a label to SwiftUI Textfield inside a SwiftUI Form so that the label is aligned with the other controls? Placeholder in textfields will disappear when you enter values so this won't help much. All other controls have labels in macOS form with the same width so that their controls are correctly aligned. Textfield seems not to have this option. I tried several workaround like HStacks of Text and Textfields or custom alignment guides but without success.
2
1
4.3k
Oct ’20
How to implement a Xcode style SwiftUI tabview
Above Xcode's navigator area or uitilty area there are some buttons for switching the content views below. I implemented the standard SwiftUI TabView and also a Picker with the segmented style to get the same appearance in my macOS app but both are looking different. Plain buttons in a HStack above my content area are solving the problem. But it seems more like a workaround. Is there maybe a simpler solution to implement a Xcode style tabview that I have overseen.
0
0
463
Oct ’20
Metal Triple Buffering and Capture Scope
Can someone help me with this hopefully simple problem? I use triple buffering in my metal app similar to Apples Best Practice Guide. Three threads are simultaneously encoding rendering commands to command buffers enqueued in into one MTLCommandQueue. What is the best way to debug this scenario with the Xcode's frame debugger? I have some problems setting the capture scopes begin and end point in such a multithreaded environment to isolate the commands encoded from one thread.
1
0
977
Oct ’20
Xcode app cannot see the driver anymore on Big Sur
My app uses an external PCI board connected with the thunderbolt cable to a 2019 MacBook Pro (Big Sur beta 10). The strange thing is that the external example apps coming with the driver can communicate with it. The same apps compiled with Xcode 12.2 beta cannot communicate with the driver even it is the same code. When I installed the driver together with the example apps a window appeared that these software come from an external source and the usage must be granted in the security settings. I did it and therefor the apps work fine. Is there maybe a similar setting now in Xcode where I must allow the compiled app to communicate with third party drivers? The code of the app was unchanged and worked with a previous macOS version.
3
0
986
Oct ’20
Search for max value coordinate in a MTLTexture
I struggle with the implementation of a compute kernel to solve a relative simple search problem. I want to find the coordinate with the highest pixel value within a MTLTexture. I have already an implementation where I copy the content of the MTLTexture into CPU memory and apply some min/max commands from the accelerate framework. But maybe there is also a simple solution for this task using Metal which I haven't found yet.
1
0
1k
Jan ’21
High battery drain using Xcode 13
I have two Mac Book Pro 16'' 2019. On both I see a very high battery drain using Xcode 13 while using the simulator. Even when the app is not running only the simulator is launched in the background the MacBook gets very hot and the battery drains empty very fast. For the beta this was ok. But with the RC I expected that this was only a temporary problem. Does some else has this problem also?
16
1
6.7k
Sep ’21
Updates on SwiftUI list causes detail views to pop
I found this problem many times in the internet but not a solution for this. I have a SwiftUI list with data fetched from a server. The app uses a periodically background sync (into a core data background context). So the rows of this list can change. To make it simple to understand think of a message app like on the iPhone: struct MasterView: View {     @FetchRequest(         sortDescriptors: [NSSortDescriptor(keyPath: \Chat.name, ascending: true)],         animation: .none)     private var chats: FetchedResults<Chat>     var body: some View {         List {             ForEach(chats, id: \.chatID) { chat in                 NavigationLink(destination: DetailView(chat: chat)) {                     Text(chat.name ?? "")                 }             }         }     } } The detail view is not so important here but keeping with the example of a message app you would have something like the following code to display the messages of a selected chat: struct DetailView: View {     let chat: Chat     @FetchRequest(         sortDescriptors: [NSSortDescriptor(keyPath: \Message.timestamp, ascending: true)],         animation: .none)     private var messages: FetchedResults<Message>     var body: some View {         List {             ForEach(messages, id: \.messageID) { message in                 Text(message.messageText ?? "")             }         }         .onAppear {             if let chatID = chat.chatID {                 messages.nsPredicate = NSPredicate(format: "chatID == %@", chatID)             }         }     } } In the internet I saw also other examples without using core data for the master view. If the details view is visible to the user and the master view receives new data from the server the details view will always close (pops) automatically. This happens also when the chatID has not changed and still exists. A change of the master or also if in a split view the master view scrolls outside the visible area then the detail screen will close. As you see I specified the item ids in both ForEach lists and added also in some further tests identifiers to the NavigationLink or destination of the NavigationLink. But as soon the master list updates the old NavigationLink seems to get deallocated and therefore the detail views will close. Does someone know how to fix this? Of course I could add a button inside the masters list, store the selection and place the NavigationLink outside from the list item as I saw in one example, but it seems to be more a quick hack as a good solution.
0
0
704
Oct ’21
Partial core data updates in Swift
Maybe I misunderstood the the 2019 WWDC video 'Making apps with core data'. Because when I use NSBatchInsertRequest together with NSMergeByPropertyObjectTrumpMergePolicy and unique constraints I can only add new records with the given id. Existing core data objects will not be partially updated. Example Entity: Person Attributes: FirstName = John LastName = Appleseed ID = 1234 (unique constraint) Goal in this example should be to change only the FirstName. As far as I understood the session video we can omit some attributes and call NSBatchInsertRequest with the above ID and change FirstName to 'Johnny'. But this seems not to work. Maybe someone has an idea if I am doing something wrong here or if this is really not possible to omit values and change single attribute values. I want to avoid fetching existing records, updating the values that should be changed and committing the changes back to the persistent store if there is maybe a better solution.
0
0
763
Dec ’21
How to deactivate SwiftUI toolbar animation
I have a simple SwiftUI List view with a .toolbar modifier containing three ToolbarItems. The placement is set to bottom. On the iPhone it seems as if the toolbar is animating from the bottom right corner whenever I launch the app. Having this view as a destination view it looks really strange. The NavigationLink causes the List view to appear from the right while the toolbar slides in from the bottom right corner. Is there a way to make the bottom toolbar not to slide it from the corner?
0
0
661
Jun ’22